<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    if (!window.Worker) {
        alert("你的电脑不支持web Workers");
    }
    var worker = new Worker("a.js");



    worker.onerror = function(e){
        console.log(e.message); //报错信息
        console.log(e.filename); //报错文件路径
    };
    worker.postMessage(10000000);
    worker.onmessage = function (event) {
        alert(event.data)
    }



    function add(x,y,callback) {
        setTimeout(function () {
            var ret = x+y
            callback(ret)
        })
    }

    add(10,20,function (data) {
        window.alert(data)
    })



//    function calculate(){
//        var ret = 0;
//        for(var i = 1; i <= 1e9; i++){
//            ret += i;
//        }
//        return ret;
//    }
//    var result;
//    var start;
//    var end;
//    start = +new Date();
//    result = calculate();
//    end = +new Date();
//    console.log(result); //500000000067109000
//    console.log(end - start); //977
//


</script>
</body>
</html>